//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#include <ddk.h>
#include <drvpub.h>

#include <bvd1bd.h>
#include <bulverde.h>
#include <Bvd1.h>

EXTERN_C void hexouts(UInt8* buf, UInt32 buflen);

EXTERN_C void __cdecl DumpGpio()
{
    kprintf("GPLR0 : %08x\n", GPLR0);
    kprintf("GPLR1 : %08x\n", GPLR1);
    kprintf("GPLR2 : %08x\n", GPLR2);
    kprintf("GPLR3 : %08x\n", GPLR3);

    kprintf("GPDR0 : %08x\n", GPDR0);
    kprintf("GPDR1 : %08x\n", GPDR1);
    kprintf("GPDR2 : %08x\n", GPDR2);
    kprintf("GPDR3 : %08x\n", GPDR3);

    kprintf("GRER0 : %08x\n", GRER0);
    kprintf("GRER1 : %08x\n", GRER1);
    kprintf("GRER2 : %08x\n", GRER2);
    kprintf("GRER3 : %08x\n", GRER3);

    kprintf("GFER0 : %08x\n", GFER0);
    kprintf("GFER1 : %08x\n", GFER1);
    kprintf("GFER2 : %08x\n", GFER2);
    kprintf("GFER3 : %08x\n", GFER3);

    kprintf("GEDR0 : %08x\n", GEDR0);
    kprintf("GEDR1 : %08x\n", GEDR1);
    kprintf("GEDR2 : %08x\n", GEDR2);
    kprintf("GEDR3 : %08x\n", GEDR3);
}

EXTERN_C Boolean __cdecl EditMemory(long offset, long *valst, long lstlen)
{
    long idx, *memstart;
    Boolean ret = TRUE;
    kprintf("Edit Memory from offset :%08x length : %08x\n",
             offset, lstlen);
    memstart = (long*)offset;
    //Start Edit memory
    for(idx = 0; idx < lstlen; idx++) {
        *(memstart + idx) = valst[idx];
    }
    //Compare Memory,Comfirm The Value Change Is Succeeded
    for(idx = 0; idx < lstlen; idx++) {
        if(*(memstart + idx) != valst[idx]) {
            kprintf("The Memory Offset : %08x havn't Edit correct!\n \
                     It may be a Read Only Register!\n", memstart + idx);
            ret = FALSE;
        }
    }
    return ret;
}

EXTERN_C void __cdecl ViewMemory(long offset, long length)
{
    UInt8 *memstart = (UInt8*)offset;
    hexouts(memstart, length);
}


EXTERN_C ECode __cdecl CallServiceFunc(wchar_t *SerName, int OpCode)
{
    ECode ec = NOERROR;
    IDeviceDriver *pDev = NULL;
    ec = DzFindService(SerName, (IInterface **)&pDev);
    if (FAILED(ec)) {
        kprintf("FIND SERVICE %S Failed!\n", SerName);
        goto __Exit;
    }

    ec = pDev->Control(OpCode, NULL_MEMORYBUF, NULL, NULL);
    if (FAILED(ec)) {
        kprintf("Call Service Control Function Faild : %08x!\n", ec);
        goto __Exit;
    }
__Exit:
    if (pDev) {
        pDev->Release();
    }
    return ec;
}




